<template>
	<view>
		<cu-custom bgColor="theme-bg-color" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">班级</block>
		</cu-custom>
		<form v-if="formData!=null">
			<view class="cu-form-group">
				<view class="title">标题</view>
				<input placeholder="请输入标题" v-model="formData.Title"></input>
			</view>
			<cu-select-picker Url="/TopicType/List" v-model="formData.TopicTypeId" Title="话题类型"></cu-select-picker>
			<cu-upload-image title="封面" limit="1" v-model="formData.Cover"></cu-upload-image>
			<cu-upload-image title="主图" limit="4" v-model="formData.ImageUrls"></cu-upload-image>
			<view class="cu-form-group align-start">
				<view class="title">话题内容</view>
				<textarea maxlength="-1" placeholder="请输入话题内容" v-model="formData.Content"></textarea>
			</view>
			<view class="padding margin-top">
				<button class="cu-btn block theme-bg-color margin-tb-sm lg" @click="Save()">提交</button>
			</view>
		</form>


	</view>


</template>

<script>
	import store from "@/store";
	import {
		mapGetters
	} from "vuex";
	export default {
		data() {
			return {
				TopicId: null,
				formData: null,


			}
		},
		computed: {
			...mapGetters(["userInfo", 'userId']),
		},
		onLoad(option) {
			this.TopicId = option.TopicId;
		},
		onShow(option) {

			
			this.GetTopicApi();
		},
		methods: {
			async GetTopicApi() {
				let {
					Data
				} = await this.$http.PostAsync("/Topic/Get", {
					CheckUserId: this.userInfo.Id,
					Id: this.TopicId
				});
				this.formData = Data;

			},
			async Save() {
				let confirm = await this.$comm.ShowModal("你确定要提交吗?");

				if (confirm == false) {
					await this.$comm.ShowToast("用户放弃操作");
					return;
				}
				let {
					Data,
					Success,
				} = await this.$http.PostAsync("/Topic/CreateOrEdit", this.formData);
				if (Success) {
					await this.$comm.ShowToast("提交成功");
					await this.$comm.ReturnPage();
				}
			}


		}
	}
</script>

<style>


</style>